from BeautifulSoup import *

class xtree:
    title = ""
    value = ""
    items = list()
    def init(self, title):
        self.title = title
        self.items = []
    def append(self, title):
        n = xtree() 
        n.init(title)
        self.items.append(n)
        return self.items[len(self.items)-1]
    def render(self):
        s = ""
        if len(self.items) > 0:           
            for i in xrange(0, len(self.items)):
                s += self.items[i].render()
            return "<"+self.title+">"+s+"</"+self.title+">"
        elif self.value != "":
            return "<"+self.title+">"+self.value+"</"+self.title+">"
        elif len(self.items) == 0:
            return "<"+self.title+"/>"
        else:
            return ""
        
class xforest(xtree):
    def init(self):
        self.items = []
    def render(self):
        s = ""
        if len(self.items) > 0:           
            for i in xrange(0, len(self.items)):
                s += self.items[i].render() + "\n"
            return s
        else:
            return ""

def xmsgproc(msg):
    return BeautifulStoneSoup(msg).message

